from rest_framework.response import Response
from rest_framework.viewsets import ModelViewSet
from goods.models import SPUSpecification, SPU
from meiduo_admin import my_serializers
from meiduo_admin.views.users import UserPageNum


class SpecsView(ModelViewSet):
    '''
    因为我们使用的视图集 ModelViewset 封装了 ’增删查改‘ 功能，所以使用这个视图集完成全套功能
    '''
    # 指定需要的序列化器
    serializer_class = my_serializers.SPUSpecificationSerializer
    # 指定查询集
    queryset = SPUSpecification.objects.all()
    # 指定分页器
    pagination_class = UserPageNum

    def simple(self, request):
        """
        获取简化的SPU数据
        """
        spus = SPU.objects.all()
        ser = my_serializers.SPUSerializer(spus, many=True)
        return Response(ser.data)





